public class demo1 {
    public static int binarySerach(int[] nums,int target,boolean flag) {
        int left=0;
        int right=nums.length-1;
        int mid;
        int ans=0;
        while(left<right) {
            mid=(left+right)>>>1;
            if(nums[mid]<target || (nums[mid]==target && flag ==false)) {
                left=mid+1;
            } else if((flag==true && nums[mid]==target) || nums[mid]>target) {
                right=mid-1;
                ans=mid;
            }
        }
        return ans;
    }
    public int[] searchRange(int[] nums, int target) {
        //ture时查找第一个，false时查找第二个
        int fistDex=binarySerach(nums,target,true);
        int lastDex=binarySerach(nums,target,false)-1;
        return new int[]{fistDex,lastDex};
    }
    public static void main(String[] args) {

    }
}
